
//309.买卖股票的最佳时机含冷冻期
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        //分三种情况:有股票f, 没股票g ,冷冻期h
        const int INF = -0x3f3f3f3f;
        int n = prices.size();
        vector<int> f(n,INF);
        auto g = f , h = f;
        f[0] = -prices[0] , g[0] = 0 ;
        for(int i = 1 ;i < n; i++)
        {
            f[i] = max(f[i-1] ,g[i-1] - prices[i]);
            g[i] = max(g[i-1] ,h[i-1]);
            h[i] = f[i-1] + prices[i];
        }
        return max(ranges::max(g),ranges::max(h));
    }
};